//
//  ViewController.m
//  11206
//
//  Created by student on 16/3/3.
//  Copyright © 2016年 niit. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong) NSDictionary *teams;
@property (nonatomic,strong) NSArray *orders;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    NSString *path = [[NSBundle mainBundle] pathForResource:@"team dictionary" ofType:@"plist"];
    self.teams = [NSDictionary dictionaryWithContentsOfFile:path];
    self.orders = [[self.teams allKeys]sortedArrayUsingSelector:@selector(compare:)];
    
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSString *group = self.orders[section];
    NSArray *selectedgroup = self.teams[group];
    return selectedgroup.count;
    
}

// Row display. Implementers should *always* try to reuse cells by setting each cell's reuseIdentifier and querying for available reusable cells with dequeueReusableCellWithIdentifier:
// Cell gets various attributes set automatically based on table (separators) and data source (accessory views, editing controls)

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    NSString *group = self.orders[indexPath.section];
    NSArray *selectedgroup = self.teams[group];
    cell.textLabel.text = selectedgroup[indexPath.row];
    return cell;
}

//@optional

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.teams.count;
}// Default is 1 if not implemented

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    NSString *key = self.orders[section];
    return key;
}

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
    return self.orders;
    
}


@end
